//
//  BillViewController.m
//  ShareYOU
//
//  Created by 杨亭 on 14-12-22.
//  Copyright (c) 2014年 ShareYOU. All rights reserved.
//

#import "BillViewController.h"
#import <QuartzCore/QuartzCore.h>
#import "Payout.h"
#import "DataBaseHandler.h"

@interface BillViewController ()

@end

@implementation BillViewController

@synthesize pickerArrayType;

//初始化
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}



- (void)viewDidLoad {
    [super viewDidLoad];
    //设置背景图片
//    self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"accountModule_background.png"]];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    CGFloat width = self.view.frame.size.width / 2;
    CGFloat height = self.view.frame.size.height / 9 ;

    //view显示
    //金额输入
    self.moneyTextField = [[UITextField alloc] initWithFrame:CGRectMake(30, height, width - 40, 45)];
//    self.moneyTextField.backgroundColor = [UIColor whiteColor];
    self.moneyTextField.delegate = self;
//    self.moneyTextField.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"accountModule_button.png"]];
    self.moneyTextField.tag = 2;
//    //设置圆角边框，先给一个圆角半径的值
//    self.moneyTextField.layer.cornerRadius = 10;
//    self.moneyTextField.layer. masksToBounds = YES;
    //设置边框颜色
    self.moneyTextField.layer.borderWidth = 2;
    self.moneyTextField.layer.borderColor = [[UIColor colorWithRed:0.3 green:0.7 blue:1 alpha:1] CGColor];
    [self.view addSubview:self.moneyTextField];
    
    
     //消费类别输入
    self.typeTextField = [[UITextField alloc] initWithFrame:CGRectMake(30, height * 2, width - 40, 45)];
//    self.typeTextField.backgroundColor = [UIColor whiteColor];
    self.typeTextField.delegate = self;
    self.typeTextField.placeholder = @"请选择消费类别";
//    self.typeTextField.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"accountModule_button.png"]];
    self.typeTextField.tag = 3;
//    //设置圆角边框，先给一个圆角半径的值
//    self.typeTextField.layer.cornerRadius = 10;
//    self.typeTextField.layer. masksToBounds = YES;
    //设置边框颜色
    self.typeTextField.layer.borderWidth = 2;
    self.typeTextField.layer.borderColor = [[UIColor colorWithRed:0.3 green:0.7 blue:1 alpha:1] CGColor];
    [self.view addSubview:self.typeTextField];
    
    
    //时间输入
    self.dateTextField = [[UITextField alloc] initWithFrame:CGRectMake(width + 10, height, width - 40, 45)];
    self.dateTextField.delegate = self;
//    self.dateTextField.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"accountModule_button.png"]];
    self.dateTextField.placeholder = @"请选择消费日期";
    self.dateTextField.tag = 4;
//    //设置圆角边框，先给一个圆角半径的值
//    self.dateTextField.layer.cornerRadius = 10;
//    self.dateTextField.layer. masksToBounds = YES;
    //设置边框颜色
    self.dateTextField.layer.borderWidth = 2;
    self.dateTextField.layer.borderColor = [[UIColor colorWithRed:0.3 green:0.7 blue:1 alpha:1] CGColor];
    [self.view addSubview:self.dateTextField];
    
    
    //消费成员输入
    self.personnelTextField = [[UITextField alloc] initWithFrame:CGRectMake(width + 10, height * 2, width - 40, 45)];
    self.personnelTextField.backgroundColor = [UIColor whiteColor];
    self.personnelTextField.delegate = self;
//    self.personnelTextField.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"accountModule_button.png"]];
//    //设置圆角边框，先给一个圆角半径的值
//    self.personnelTextField.layer.cornerRadius = 10;
//    self.personnelTextField.layer. masksToBounds = YES;
    //设置边框颜色
    self.personnelTextField.layer.borderWidth = 2;
    self.personnelTextField.layer.borderColor = [[UIColor colorWithRed:0.3 green:0.7 blue:1 alpha:1] CGColor];
    self.personnelTextField.placeholder = @"请选择消费成员";
    self.personnelTextField.tag = 5;
    [self.view addSubview:self.personnelTextField];
    

    //备注输入
    self.commentTextField = [[UITextView alloc] initWithFrame:CGRectMake(30, height * 3, width * 2 - 60, 80)];
//    self.commentTextField.backgroundColor = [UIColor whiteColor];
    self.commentTextField.text = @"备注";
    //字体颜色
    self.commentTextField.textColor = [UIColor blackColor];
    //设置字体大小
    self.commentTextField.font = [UIFont fontWithName:@"Arial" size:18];
    self.commentTextField.delegate = self;
    self.commentTextField.backgroundColor = [UIColor whiteColor];
    //设置自定义高度
    self.commentTextField.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    //是否可以拖动,默认YES。关闭暂时拖着任何
    self.commentTextField.scrollEnabled = YES;
    //是否可以编辑
    self.commentTextField.editable = YES;
//    //设置圆角边框，先给一个圆角半径的值
//    self.commentTextField.layer.cornerRadius = 10;
//    self.commentTextField.layer. masksToBounds = YES;
    //设置边框颜色
    self.commentTextField.layer.borderWidth = 2;
    self.commentTextField.layer.borderColor = [[UIColor colorWithRed:0.3 green:0.7 blue:1 alpha:1] CGColor];
    self.commentTextField.tag = 6;
    [self.view addSubview:self.commentTextField];
    
    
    
    //显示输入剩余字数
    self.surplusInputLabel = [[UILabel alloc] initWithFrame:CGRectMake(width * 2 - 80, height * 3 + 60, 60, 20)];
    self.surplusInputLabel.text = @"18/18";
    [self.view addSubview:self.surplusInputLabel];

    
    
    
    //保存按钮
    self.saveButton = [UIButton buttonWithType:UIButtonTypeSystem];
//    self.saveButton.backgroundColor = [UIColor whiteColor];
    self.saveButton.frame = CGRectMake(50, height * 5, 100, 40);
    [self.saveButton setTitle:@"保存" forState:UIControlStateNormal];
    self.saveButton.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"accountModule_button.png"]];
    [self.saveButton addTarget:self action:@selector(saveApayout:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.saveButton];
    
    //清空按钮
    self.clearButton = [UIButton buttonWithType:UIButtonTypeSystem];
//    self.clearButton.backgroundColor = [UIColor whiteColor];
    self.clearButton.frame = CGRectMake(width * 2 - 150, height * 5, 100, 40);
    [self.clearButton setTitle:@"清空" forState:UIControlStateNormal];
    self.clearButton.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"accountModule_button.png"]];
    [self.clearButton addTarget:self action:@selector(clearButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.clearButton];
   
    //返回按钮实现
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回"  style:UIBarButtonItemStylePlain target:self action:@selector(backBtnAction)];//UIBarButtonItem
    //手势实现
    [self initHandle];
    
    //pickerView的实现
    [self initPicker];

    //数据处理
    //单例的使用
    DataBaseHandler *dataHandler = [DataBaseHandler shareInstance];
    
    [dataHandler openDB];


    
}


//显示剩余可输入字数
- (void)textViewDidChange:(UITextView *)textView {
    NSInteger number = [textView.text length];
    if (number > 18) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"已经输入18个字了哦!" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alert show];
        textView.text = [textView.text substringToIndex:18];
        number = 18;
        [alert release];
    }
    
    self.surplusInputLabel.text = [NSString stringWithFormat:@"%ld/18",18 - number];
}





//手势方法实现
-(void)initHandle{
    self.navigationItem.title= @"记一笔";
    self.pickerArrayType = [[NSArray alloc]init];
    UISwipeGestureRecognizer *recognizer;
    if ([self.backTypeNSString isEqualToString:@"Dtype"]) {
        recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];
        
        [recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
        
        [[self view] addGestureRecognizer:recognizer];
    }else if([self.backTypeNSString isEqualToString:@"View"]){
        recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];
        
        [recognizer setDirection:(UISwipeGestureRecognizerDirectionDown)];
        
        [[self view] addGestureRecognizer:recognizer];
        
    }
    
}
//返回按钮方法的实现
-(void)backBtnAction{
    if ([self.backTypeNSString isEqualToString:@"Dtype"]) {
        [self.navigationController popViewControllerAnimated:YES];
    }
    CATransition*transition=[CATransition animation];
    transition.duration=0.5;
    transition.timingFunction= UIViewAnimationCurveEaseInOut;
    transition.type=kCATransitionPush;
    transition.subtype=kCATransitionFromBottom;//方向
    
    [self.navigationController.view setBackgroundColor:[UIColor whiteColor]];
    [self.navigationController.view.layer addAnimation:transition forKey:nil];
    
    [self.navigationController popViewControllerAnimated:NO];
    
}

//保存按钮方法实现
- (void)saveApayout:(UIButton *)saveButton
{
    //判断金额不能为空
    if ([self.moneyTextField.text length] == 0) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"金额不能为空！" message:nil delegate:nil cancelButtonTitle:@"OK!" otherButtonTitles:nil, nil];
        [alert show];
        [alert release];
    }else if ([self.typeTextField.text length] == 0) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"消费类别不能为空！" message:nil delegate:nil cancelButtonTitle:@"OK!" otherButtonTitles:nil, nil];
        [alert show];
        [alert release];
    }else if ([self.dateTextField.text length] == 0) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"消费时间不能为空！" message:nil delegate:nil cancelButtonTitle:@"OK!" otherButtonTitles:nil, nil];
        [alert show];
        [alert release];
    }else if ([self.personnelTextField.text length] == 0) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"消费成员不能为空！" message:nil delegate:nil cancelButtonTitle:@"OK!" otherButtonTitles:nil, nil];
        [alert show];
        [alert release];
    }else if ([self.personnelTextField.text length] == 0) {
        self.personnelTextField.text = @"没有备注";
    }
    else
    {

        //单例的使用
        DataBaseHandler *dataHandler = [DataBaseHandler shareInstance];
        
        //打开数据库(调用)
        [dataHandler openDB];
        
        //创建表成功
        [dataHandler createWriteTable];
        
        //添加数据
        Payout *payout = [[Payout alloc] init];
//        Payout *pay = [self.pickerArrayType objectAtIndex:row];
//        NSArray *payArr = [pay.payout_ID componentsSeparatedByString:@" "];
//
        
//        payout.payout_ID = ;
        NSLog(@"++++++++++++++++%ld", payout.payout_ID);
        payout.amount = self.moneyTextField.text;
        payout.type = self.typeTextField.text;
        payout.date = self.dateTextField.text;
        payout.personnel = self.personnelTextField.text;
        payout.comment = self.commentTextField.text;
        
        [dataHandler insertWritePayout:payout];
        
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"保存成功！" message:nil delegate:nil cancelButtonTitle:@"OK!" otherButtonTitles:nil, nil];
        [alert show];
      
    }
    
    
    
}
//清除按钮方法实现
- (void)clearButton:(UIButton *)clearButton
{
 UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"删除成功！" message:nil delegate:nil cancelButtonTitle:@"OK!" otherButtonTitles:nil, nil];
        [alert show];
        [self clearBill];
}
////传值
//-(void)aPayout
//{
//    
//    
//}
//手势方法的实现
-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer{
    if(recognizer.direction==UISwipeGestureRecognizerDirectionRight) {
        
        [self.navigationController popViewControllerAnimated:YES];
        
    }
    if(recognizer.direction==UISwipeGestureRecognizerDirectionDown) {
        CATransition*transition=[CATransition animation];
        transition.duration=0.5;
        transition.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
        transition.type=kCATransitionPush;
        transition.subtype=kCATransitionFromBottom;//方向
        
        [self.navigationController.view setBackgroundColor:[UIColor whiteColor]];//
        [self.navigationController.view.layer addAnimation:transition forKey:nil];
        
        [self.navigationController popViewControllerAnimated:NO];
        
    }
    
}



//初始化pickerview
-(void)initPicker{
    //type picker
    if (self.typePicker == nil) {
        self.typePicker = [[UIPickerView alloc] init];
        self.typePicker.delegate = self;
        //显示选中框
        self.typePicker.showsSelectionIndicator = YES;
    }
    //date picker
    if (self.datePicker == nil) {
        self.datePicker = [[UIDatePicker alloc]init ];
        [self.datePicker addTarget:self action:@selector(datePickerChanged:) forControlEvents:UIControlEventValueChanged];
        self.datePicker.datePickerMode = UIDatePickerModeDate;
        NSDate * currentDate = [NSDate date];
        NSDateComponents *dateComponents = [[NSDateComponents alloc]init ];
        [dateComponents setYear:-18];
        NSDate *selectedDate = [[NSCalendar currentCalendar]dateByAddingComponents:dateComponents toDate:currentDate options:0 ];
        [self.datePicker setDate:selectedDate animated:YES];
        self.datePicker.date=[NSDate new];
        [self.datePicker setMaximumDate:currentDate];
    }
    // person Picker
    if (self.personPickerView == nil) {
        self.personPickerView = [[UIPickerView alloc]init ];
        self.personPickerView.delegate = self;
        self.personPickerView.showsSelectionIndicator = YES;
    }
    //Keyboard toolbar
    if (self.keyboardToolbar == nil) {
        self.keyboardToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 38.0f)];
        self.keyboardToolbar.barStyle = UIBarStyleBlackTranslucent;
        UIBarButtonItem *previousBarItem = [[UIBarButtonItem alloc]initWithTitle:NSLocalizedString(@"上一个", @"") style:UIBarButtonItemStyleBordered target:self action:@selector(previousField:) ];
        UIBarButtonItem * nextButtonItem = [[UIBarButtonItem alloc]initWithTitle:NSLocalizedString(@"下一个", @"") style:UIBarButtonItemStyleBordered target:self action:@selector(nextField:) ];
        UIBarButtonItem *spaceBarItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
        UIBarButtonItem *doneBarItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"确定", @"")style:UIBarButtonItemStyleDone target:self action:@selector(resignKeyboard:)];
        [self.keyboardToolbar setItems:[NSArray arrayWithObjects:previousBarItem,nextButtonItem,spaceBarItem,doneBarItem, nil]];
        self.moneyTextField.inputAccessoryView = self.keyboardToolbar;
        self.typeTextField.inputAccessoryView = self.keyboardToolbar;
        self.dateTextField.inputAccessoryView = self.keyboardToolbar;
        self.personnelTextField.inputAccessoryView = self.keyboardToolbar;
        self.commentTextField.inputAccessoryView = self.keyboardToolbar;
        self.typeTextField.inputView = self.typePicker;
        self.dateTextField.inputView = self.datePicker;
        self.personnelTextField.inputView = self.personPickerView;
    }
    //set localization
    self.moneyTextField.placeholder = NSLocalizedString(@"请输入money", @"");
    self.typeTextField.text = [NSLocalizedString(@"", @"")uppercaseString];
    self.dateTextField.text = [NSLocalizedString(@"", @"")uppercaseString];
    self.personnelTextField.text = [NSLocalizedString(@"", @"")uppercaseString];
    self.commentTextField.text = [NSLocalizedString(@"备注", @"")uppercaseString];
    self.commentTextField.text=@" ";
    
}

//键盘上一个的实现
-(void)previousField:(id)sender
{
    id firstResponder = [self getFirstResponder];
    if ([firstResponder isKindOfClass:[UITextField class]]||[firstResponder isKindOfClass:[UITextView class]]) {
        NSUInteger tag = [firstResponder tag];
        NSUInteger previousTag = tag == 1 ? 1 :tag - 1;
//        [self checkBarButton:previousTag];
//        [self animateView:previousTag];
        UITextField * previousField = (UITextField *)[self.view viewWithTag:previousTag];
        [previousField becomeFirstResponder];

    }

    
}
//键盘下一个的实现
- (void)nextField:(id)sender
{
    id firstResponder = [self getFirstResponder];
    if ([firstResponder isKindOfClass:[UITextField class]]) {
        NSUInteger tag = [firstResponder tag];
        NSUInteger nextTag = tag == 6 ? 6 : tag + 1;
//        [self checkBarButton:nextTag];
//        [self animateView:nextTag];
        UITextField *nextField = (UITextField *)[self.view viewWithTag:nextTag];
        [nextField becomeFirstResponder];
    }
}

//键盘确定方法实现
-(void)resignKeyboard:(id)sender
{
    if (self.mark == 0) {
        Payout *pay = [self.pickerArrayType objectAtIndex:[self.typePicker selectedRowInComponent:0]];
        NSArray *payArr = [pay.type componentsSeparatedByString:@" "];
        self.typeTextField.text = [payArr lastObject];
    }
    else if(self.mark == 1){
        Payout *pay = [self.pickerArrayPerson objectAtIndex:[self.personPickerView selectedRowInComponent:0]];
        NSArray *payArr = [pay.personnel componentsSeparatedByString:@" "];
        self.personnelTextField.text = [payArr lastObject];
    }
    else if (self.mark == 2) {
        [self.commentTextField resignFirstResponder];
    }
    else if (self.mark == 3) {
        [self.moneyTextField resignFirstResponder];
    }
    else if (self.mark == 4)
    {
        [self setDateData];
    }
   
    

   
    //如果点击确定回收键盘
    id firstResponder = [self getFirstResponder];
    //找出第一个响应者让键盘回收
    if ([firstResponder isKindOfClass:[UITextField class]]||[firstResponder isKindOfClass:[UITextView class]]) {
        [firstResponder resignFirstResponder];
    }
    
}



//回收键盘的实现
- (id)getFirstResponder
{
    NSUInteger index = 0;
    while (index <= 6) {
        UITextField *textField = (UITextField *)[self.view viewWithTag:index];
        if ([textField isFirstResponder]) {
            return textField;
        }
        index++;
    }
    return nil;
}



//- (void)animateView:(NSUInteger)tag
//{
//    
//    CGRect rect = self.view.frame;
//    [UIView beginAnimations:nil context:NULL];
//    [UIView setAnimationDuration:0.3];
//    
//    if (tag > 3) {
//        rect.origin.y = -44.0f * (tag - 3);
//    } else {
//        rect.origin.y = 0;
//    }
//    self.view.frame = rect;
//    [UIView commitAnimations];
//}
//
//- (void)checkBarButton:(NSUInteger)tag
//{
//   
//    UIBarButtonItem *previousBarItem = (UIBarButtonItem *)[[self.keyboardToolbar items] objectAtIndex:0];
//    UIBarButtonItem *nextBarItem = (UIBarButtonItem *)[[self.keyboardToolbar items] objectAtIndex:1];
//    [previousBarItem setEnabled:tag == 1 ? NO : YES];
//    [nextBarItem setEnabled:tag == 7 ? NO : YES];
//}
//
//- (void)checkSpecialFields:(NSUInteger)tag
//{
//    if (tag == 4 && [self.dateTextField.text isEqualToString:@""]) {
//        [self setDateData];
//    } else if (tag == 5 && [self.personnelTextField.text isEqualToString:@""]) {
//        [self setPersonData];
//    }else if (tag == 3 && [self.typeTextField.text isEqualToString:@""]) {
//        [self setTypeData];
//    }else if (tag == 6 && [self.commentTextField.text isEqualToString:@""]) {
//        [self setComment];
//    }
//}


//datePicker的方法
-(void)datePickerChanged:(id)sender
{
    [self setDateData];
}

//datePicker的实现
-(void)setDateData
{
    
    NSDateFormatter * dateFormatter = [[NSDateFormatter alloc]init ];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    [self.datePicker setAccessibilityLanguage:@"Chinese"];
    
    self.theDate = self.datePicker.date;
    [dateFormatter setLocale:[NSLocale currentLocale]];
    self.dateTextField.text = [dateFormatter stringFromDate:self.theDate];
    
}

//备注的实现
-(void)setComment
{
    self.commentTextField.text = @"a";

    
}
#pragma mark 类型选择的实现
-(void)setTypeData:(NSUInteger)row
{
    Payout *pay = [self.pickerArrayType objectAtIndex:row];
    NSArray *payArr = [pay.type componentsSeparatedByString:@" "];
    self.typeTextField.text = [payArr lastObject];
    
}
//成员选择的实现
-(void)setPersonData:(NSUInteger)row
{
    Payout *pay = [self.pickerArrayPerson objectAtIndex:row];
    NSArray *payArr = [pay.personnel componentsSeparatedByString:@" "];
    self.personnelTextField.text = [payArr lastObject];
   
}


//返回显示的列数
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
    
}

//返回当前列显示的行数
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if (self.mark == 0) {
        return [self.pickerArrayType count];
    }else if(self.mark == 1)
    {
        return [self.pickerArrayPerson count];
    }
    return 1;
}


//设置当前行内容
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if (self.mark == 0) {
        Payout *pay = [self.pickerArrayType objectAtIndex:row];
        NSArray *payArr = [pay.type componentsSeparatedByString:@" "];
        return [payArr objectAtIndex:0];
    }else if(self.mark == 1){
        Payout *pay = [self.pickerArrayPerson objectAtIndex:row];
        NSArray *payArr = [pay.personnel componentsSeparatedByString:@" "];
        return [payArr objectAtIndex:0];
    }
    return nil;
    
}





//选中pickerView内容执行方法
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component 
{

    if (self.mark == 0) {
        [self setTypeData:row];
    }else if(self.mark == 1){
        [self setPersonData:row];
    }
    
}
//
//-(BOOL)textFieldShouldEndEditing:(UITextField *)textField{
//    //    [moneyTextField resignFirstResponder];
//    return YES;
//    
//}



//开始编辑时触发，文本字段将成为first responder
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
    DataBaseHandler *dataHandler = [DataBaseHandler shareInstance];
    if (textField.tag == 3) {

        self.pickerArrayType = [dataHandler selectAllT];
        self.mark = 0;
         
    }
    else if(textField.tag == 5){
        self.pickerArrayPerson = [dataHandler selectAllP];
        self.mark = 1;
    }
    else if (textField.tag == 6) {
        self.commentTextField.keyboardType =  UIKeyboardTypePhonePad;
        self.mark = 2;
    }
    else if (textField.tag == 2) {
        
        //设置键盘
        self.moneyTextField.keyboardType =  UIKeyboardTypePhonePad;
        
        self.mark = 3;
        //键盘
    }
    else if (textField.tag == 4)
    {
        self.mark = 4;
    }

    
}



-(void)clearBill{
    self.moneyTextField.text=@"";
    self.typeTextField.text=@"";
    self.dateTextField.text=@"";
    self.commentTextField.text=@"";
    self.personnelTextField.text=@"";
    self.types=@"";
}




//释放内存
- (void)dealloc
{
    [_moneyTextField release];
    [_typeTextField release];
    [_dateTextField release];
    [_commentTextField release];
    [_typeLabel release];
    [_dateLabel release];
    [_personnelLabel release];
    [_commentLabel release];
    [_moneyLabel release];
    [_typePicker release];
    [_personPickerView release];
    [_surplusInputLabel release];
    [_datePicker release];
    [_keyboardToolbar release];
    [_backTypeNSString release];
    [_person release];
    [_theDate release];
    [_types release];
    [super dealloc];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
